package com.kommii.test;

import java.util.Date;
import java.util.List;

import com.hddf.project.auth.pojos.Authority;
import com.hddf.project.auth.service.AuthService;
import com.hddf.project.auth.service.MongoDB_Sync;

public class authtest {
	
	public static void add(){
		AuthService as = AuthService.getInstance();
		MongoDB_Sync ms = MongoDB_Sync.getInstance();
		Authority auth = new Authority();
		auth.setIsleaf(1);
		auth.setName("用户管理17");
		auth.setSort(16);
		auth.setUpdate_time(new Date());
		auth.setUrl("usermanager.jsp,user!register,user!checkUsername,user!updateUserInfo");
		auth.setUserid(1);
		auth.setUsername("super");
		auth.setState(0);
		as.addAuth(auth);
		ms.addAuth(auth.toDbObject());
	}
	
	public static void update(){
		AuthService as = AuthService.getInstance();
		MongoDB_Sync ms = MongoDB_Sync.getInstance();
	
		Authority auth = new Authority();
		auth.setId(1);
		auth.setIsleaf(1);
		auth.setName("修改密码");
		auth.setSort(2);
		auth.setUpdate_time(new Date());
		auth.setUrl("usermanager.jsp,user!register,user!checkUsername,user!updateUserInfo");
		auth.setUrl("updatepw.jsp,user!updateUserPassword");
		auth.setUserid(1);
		auth.setState(1);
		auth.setUsername("super");
		as.updateAuth(auth);
		ms.updateAuth(auth.toDbObject());
	}
	
	public static void delete(int id){
		AuthService as = AuthService.getInstance();
		MongoDB_Sync ms = MongoDB_Sync.getInstance();
		as.deleteAuth(id);
		ms.deleteAuth(id);
		
	}

	public static void getById(int id){
		AuthService as = AuthService.getInstance();
		Authority auth = as.getAuthById(id);
		System.out.println(auth.getName());
		System.out.println(auth.getUrl());
	}
	
	public static void getByName(String name){
		AuthService as = AuthService.getInstance();
		Authority auth = as.getAuthByName(name);
		System.out.println(auth.getName());
		System.out.println(auth.getUrl());
	}
	
	public static void getAuthList(String start,String limit,int state){
		AuthService as = AuthService.getInstance();
		List<Authority> list = as.getAuthList(start, limit, state);
		System.out.println(list.size());
		int s = list.size();
		Authority auth = null;
		for(int i=0;i<s ; i++){
			auth = list.get(i);
			System.out.println(auth.getName());
		}
	}
	
	public static void main(String[] args) {
		//add();
		//update();
		//delete(8);
		getById(1);
		//getByName("用户管理");
		//getAuthList(null,null,-1);
	}

}
